<style scoped>
  .header{
    display: flex;
    flex-direction: column;
  }
  .header-top{
    width:100%;
    height:10px;
    background: transparent;
  }
  .head{
    height:50px;
    padding-top: 10px;
    /*border-bottom: 2px solid #dedde3;*/
    display: flex;
    justify-content: center;
    align-items:center;
    background: #ffffff;
    box-shadow:0 2px 4px rgba(0,0,0,0.1);
    position: relative;
  }
  .head-left{
    position: absolute;
    width:40px;
    height:100%;
    left:0;
    top:0;
    color: #7f7a8e;
    text-align: center;
  }
  .head-left h1{
    margin-top: 22px;
  }
  .head-middle{
    font-size: 16px;
    color: #7f7a8e;
  }
  .head-right{
    position: absolute;
    right:14px;
    top:25px;
    color: #7f7a8e;
  }
  .content{
    width:100%;
    color: #7F7A8E;
    background: #edf1f5;
    overflow: scroll;
  }
  .content input{
    width:100%;
    height:98%;
    border: none;
  }
  .first{
    padding-top: 10px;
  }
  .second{
    padding-top: 10px;
  }
  @media screen and (max-width: 320px) {
    .content>div>ul>li{
      /*padding:10px 0;*/
      height:42px;
    }
    .content>div>ul>li .left{
      padding-left: 10px;
    }
    .content>div>ul>li .right{
      padding-right: 10px;
    }
    .content input{
      font-size: 1.5rem;
    }
    .next{
      height:35px;
    }
  }
  @media screen and (max-width:375px) and (min-width:321px) {
    .content>div>ul>li{
      height:54px;
    }
    .content>div>ul>li .left{
      padding-left: 12px;
    }
    .content>div>ul>li .right{
      padding-right: 12px;
    }
    .content input{
      font-size: 1.8rem;
    }
    .next{
      height:39px;
    }
  }
  @media screen and (min-width: 376px){
    .content>div>ul>li{
      height:66px;
    }
    .content>div>ul>li .left{
      padding-left: 18px;
    }
    .content>div>ul>li .right{
      padding-right: 18px;
    }
    .content input{
      font-size: 1.9rem;
    }
    .next{
      height:45px;
    }
  }
  .content>div>ul{
    display: flex;
    flex-direction: column;
  }
  .content>div>ul>li{
    display: flex;
    flex-direction: row;
    border-bottom: 1px solid #E9E9E9;
    background: #ffffff;
    align-items: center;
  }
  .content>div>ul>li .left{
    flex:3;
  }
  .content>div>ul>li .right{
    flex:7;
    height:100%;
    display: flex;
    align-items: center;
  }
  .content>div>ul>li .right h3{
    display: flex;
    flex: 1;
    height:100%;
    align-items: center;
  }
  .hunyin>.right>ul{
    display: flex;
    flex-direction: row;
  }
  .hunyin>.right>ul>li{
    display: flex;
    flex-direction: row;
    margin-left: 2px;
  }
  .hunyin>.right>ul>li h2{
    display: flex;
    align-items: center;
  }
  .color{
    color: #4D66FF;
  }
  .shengfen .right{
    display: flex;
    flex-direction: row;
    color: #4D66FF;
  }
  .shengfen .right h3{
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .dizhi .right{
    display: flex;
    flex-direction: row;
  }
  .dizhi .right .right2{
    margin-left: 4px;
  }
  .picker{
    width:100%;
  }
  .next{
    position: fixed;
    bottom:0;
    width:100%;
    background: #fff;
    padding-bottom: 10px;
    padding-top: 10px;
  }
  .next>a{
    height:100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #4D66FF;
    margin: 0 10px;
    border-radius: 4px;
  }
  .next>a h3{
    color: #ffffff;
  }

  .mint-popup-bottom{
    width:100%;
  }
  .information{
    background: #ffd093;
    padding: 6px 16px;
  }
</style>

<template>
  <div class="open3">
    <div class="header" ref="mykhhd" style="position: fixed;top: 0;width: 100%;z-index: 999999;height: 60px;background: white">
      <div class="head">
        <div class="head-left" @click="goBack"><h1 class="iconfont icon-xiangzuo1"></h1></div>
        <div class="head-middle"><h3>宽策略证券开户</h3></div>
        <div class="head-right"  @click="contact"><h1 class="iconfont icon-kefu3"></h1></div>
      </div>
    </div>
    <div class="content" style="margin-top: 61px;padding-bottom: 60px;" ref="contentheight" id='open3Content'>
      <div class="first">
        <ul>
          <li>
            <div class="left">
              <h3>姓</h3>
            </div>
            <div class="right">
              <input type="text" placeholder="请输入汉字姓" v-model="idMessages.na_first">
            </div>
          </li>
          <li>
            <div class="left">
              <h3>名</h3>
            </div>
            <div class="right">
              <input type="text" placeholder="请输入汉字名" v-model="idMessages.na_last">
            </div>
          </li>
          <li>
            <div class="left">
              <h3>拼音姓</h3>
            </div>
            <div class="right">
              <input type="text" placeholder="请输入拼音姓" v-model="idMessages.surname" onkeyup="this.value=this.value.toUpperCase()" style="text-transform: uppercase">
            </div>
          </li>
          <li>
            <div class="left">
              <h3>拼音名</h3>
            </div>
            <div class="right">
              <input type="text" placeholder="请输入拼音名" v-model="idMessages.firstname" onkeyup="this.value=this.value.toUpperCase()" style="text-transform: uppercase">
            </div>
          </li>
          <li>
            <div class="left">
              <h3>身份证号</h3>
            </div>
            <div class="right">
              <input type="text" placeholder="请输入身份证号" v-model="idMessages.idcard">
            </div>
          </li>
          <li class="dizhi shengfen">
            <div class="left">
              <h3>证件地址</h3>
            </div>
            <div class="right" @click="chooseHome">
              <h3>{{idMessages.location}}</h3>
              <h3>{{id_addr_shi}}</h3>
              <h2 class="iconfont" v-bind:class="{'icon-xiangxia2':xiangxia,'icon-xiangyou1':xiangyou}"></h2>
            </div>
          </li>
          <!--<li>-->
          <!--<div class="left"></div>-->
          <!--<div class="right">-->
          <!--<input type="text" placeholder="请输入市" v-model="id_addr_shi">-->
          <!--</div>-->
          <!--</li>-->
          <li>
            <div class="left"><h3>详细地址</h3></div>
            <div class="right">
              <input type="text" placeholder="请确保和身份证地址一致" v-model="id_addr">
            </div>
          </li>
          <li>
            <div class="left">
              <h3>Email</h3>
            </div>
            <div class="right">
              <input type="email" placeholder="请输入邮箱" v-model="email" required>
            </div>
          </li>
        </ul>
      </div>
      <div class="second">
        <ul>
          <li>
            <div class="left">
              <h3>抚养人数</h3>
            </div>
            <div class="right">
              <input type="number" placeholder="请输入抚养人数" v-model="raise_amount" onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))">
            </div>
          </li>
          <li class="hunyin">
            <div class="left">
              <h3>婚姻状况</h3>
            </div>
            <div class="right">
              <ul>
                <li v-for="(hunyin,index) in hunyins">
                  <h2 class="iconfont"
                      :class="{'icon-yuanxingweixuanzhong':hunyin.choose,
                      'icon-yuanxingxuanzhongfill color':hunyin.isChoose}"
                      @click="clickThis(index)"></h2>
                  <h3>{{hunyin.name}}</h3>
                </li>
              </ul>
            </div>
          </li>
          <li class="hunyin">
            <div class="left">
              <h3>就业状况</h3>
            </div>
            <div class="right">
              <ul>
                <li v-for="(jiuye,index) in jiuyes">
                  <h2 class="iconfont"
                      :class="{'icon-yuanxingweixuanzhong':jiuye.choose,
                      'icon-yuanxingxuanzhongfill color':jiuye.isChoose}"
                      @click="clickWork(jiuye, index)"></h2>
                  <h3>{{jiuye.name}}</h3>
                </li>
              </ul>
            </div>
          </li>
        </ul>
      </div>
      <div class="shougu" v-if="companyShow">
        <ul>
          <li>
            <div class="left">
              <h3>公司</h3>
            </div>
            <div class="right">
              <input type="text" placeholder="请填写公司全称,如XX有限公司" v-model="company_name">
            </div>
          </li>
          <p class="information" v-if="infor">{{information}}</p>
          <li class="shengfen">
            <div class="left">
              <h3>公司地址</h3>
            </div>
            <div class="right" @click="choosePro">
              <h3>{{province}}</h3>
              <h3>{{city}}</h3>
              <h2 class="iconfont" v-bind:class="{'icon-xiangxia2':xiangxia,'icon-xiangyou1':xiangyou}"></h2>
            </div>
          </li>
          <li v-if="proShow" style="display: flex;justify-content: center;height: 200px;">
            <!--<my-picker :slots="addressSlots" class="picker" @change="onAddressChange" :visible-item-count="5" :itemHeight="30"></my-picker >-->
          </li>
          <li>
            <div class="left">
              <h3>详细地址</h3>
            </div>
            <div class="right">
              <input type="text" placeholder="请务必精确至街道楼号" v-model="company_addr">
            </div>
          </li>
          <li>
            <div class="left">
              <h3>行业</h3>
            </div>
            <div class="right" @click="chooseIndu">
              <h3 style="display: flex">{{chooseIndustry}}</h3>
              <h2 class="iconfont icon-xiangyou1"></h2>
            </div>
          </li>
          <li v-if="industryShow" style="display: flex;justify-content: center;height: auto;">
            <!--<industry-picker :slots="industrySlots" class="picker" @change="onIndustryChange" :visible-item-count="5" :itemHeight="30"></industry-picker >-->
          </li>
          <li>
            <div class="left">
              <h3>职位</h3>
            </div>
            <div class="right">
              <input type="text" placeholder="如:产品经理,工程师" v-model="position">
            </div>
          </li>
        </ul>
      </div>
      <div class="wuye" v-if="wuye">
        <ul>
          <li>
            <div class="left">
              <h3>收入来源</h3>
            </div>
            <div class="right" @click="chooseIncome">
              <h3 >{{chooseIncomedata}}</h3>
            </div>
          </li>
          <li v-if="incomeShow" style="display: flex;justify-content: center;height: auto;">
          </li>
        </ul>
      </div>
      <div class="next" @click="next">
        <router-link to=""><h3>下一步</h3></router-link>
      </div>
    </div>

    <mt-popup0
      v-model="popupVisible0"
      v-if="mtPickerShow0"
      position="bottom">
      <div style="width: 100%;">
        <mt-picker0 :slots="addressSlots" class="picker" @change="onHomeChange"></mt-picker0>
      </div>
    </mt-popup0>
    <mt-popup1
      v-model="popupVisible1"
      v-if="mtPickerShow1"
      position="bottom">
      <div style="width: 100%;">
        <mt-picker1 :slots="addressSlots" class="picker" @change="onAddressChange"></mt-picker1>
      </div>
    </mt-popup1>
    <mt-popup2
      v-model="popupVisible2"
      v-if="mtPickerShow2"
      position="bottom">
      <div style="width: 100%;">
        <mt-picker2 :slots="industrySlots" @change="onIndustryChange"></mt-picker2>
      </div>
    </mt-popup2>
    <mt-popup3
      v-model="popupVisible3"
      v-if="mtPickerShow3"
      position="bottom">
      <div style="width: 100%;">
        <mt-picker3 :slots="incomeSlots" @change="onIncomeChange"></mt-picker3>
      </div>
    </mt-popup3>
  </div>
</template>

<script>
  import myKh from '../components/kh.vue'
  import { Popup } from 'mint-ui'
  import { Picker } from 'mint-ui'
  import s from '../assets/data/dizhi.json'
  import '../plugins/pinyin_dict_notone.js'
  import '../plugins/pinyinUtil.js'
  import axios from 'axios'
  import host from '../config.js'
  import {Toast} from 'mint-ui'


  export default {
    components: {
      myKh,
      mtPopup0: Popup,
      mtPopup1: Popup,
      mtPopup2: Popup,
      mtPopup3: Popup,
      mtPicker0: Picker,
      mtPicker1: Picker,
      mtPicker2: Picker,
      mtPicker3: Picker
//      myPicker: Picker,
//      industryPicker: Picker,
//      incomePicker: Picker
    },
    data () {
      return {
        navigator: navigator,
        mtPickerShow0: false,
        mtPickerShow1: false,
        mtPickerShow2: false,
        mtPickerShow3: false,
        popupVisible0: false,
        popupVisible1: false,
        popupVisible2: false,
        popupVisible3: false,
//        身份证信息
        idMessages: {
          na_first: null,
          na_last: null,
          surname: null,
          firstname: null,
          idcard: null,
          location: '请选择省'
        },
        id_addr_shi: '请选择市',
        id_addr: null,
        email: null,
        raise_amount: null,
        homeprovince: '请选择省',
        homecity: '请选择市',
//        婚姻状况
        // hunyins: [
        //   {name: '已婚', eng: 'married', choose: true, isChoose: false},
        //   {name: '未婚', eng: 'single', choose: true, isChoose: false},
        //   {name: '离异', eng: 'divorced', choose: true, isChoose: false},
        //   {name: '丧偶', eng: 'widowed', choose: true, isChoose: false}
        // ],
        hunyins: [],
//        就业情况
        // jiuyes: [
        //   {name: '受雇', eng: 'employed', choose: true, isChoose: false},
        //   {name: '创业', eng: 'startup', choose: true, isChoose: false},
        //   {name: '在家投资', eng: 'homeInvest', choose: true, isChoose: false}
        // ],
        jiuyes: [],
//        公司名称
        company_name: null,
//        公司地址
        company_addr: null,
//        职位
        position: null,
        //        是否显示公司
        companyShow: false,
        wuye: false,
//        省市数据
        addressSlots: [
          {
            flex: 1,
            defaultIndex: 1,
            values: Object.keys(s),
            className: 'slot1',
            textAlign: 'center'
          }, {
            divider: true,
            content: '-',
            className: 'slot2'
          }, {
            flex: 1,
            values: Object.keys(s[Object.keys(s)[0]]),
            className: 'slot3',
            textAlign: 'center'
          }
        ],
//        省市联动
        province: '请选择省份',
        city: '请选择城市',
        proShow: false,
        xiangxia: false,
        xiangyou: true,
        xiangxia2: false,
        xiangyou2: true,

//        行业数据
        // "choice" : {
        //   "education" : "教育",
        //   "financialService" : "金融服务",
        //   "publicInstitution" : "党政机关/事业单位",
        //   "medical" : "医疗与卫生保健",
        //   "IT" : "IT信息技术",
        //   "internetCommerce" : "互联网/电子商务",
        //   "media" : "媒体新闻/报纸/杂志",
        //   "estate" : "房地产相关",
        //   "retail" : "零售",
        //   "foodService" : "餐厅/食品服务",
        //   "publicService" : "社会/公共服务",
        //   "transport" : "运输与物流",
        //   "travel" : "旅游/休闲"
        // },
        "choice": {},
        industryShow: false,
        industryData: [],
        chooseIndustry: '点击选择',
        industrySlots: [
          {
            flex: 1,
            values: []
          }
        ],
//        选中的行业
        engChooseIndustry: null,
        engChooseIncome: null,
//        收入来源
        incomeShow: false,
        chooseIncomedata: '点击选择',
        "incomeChoice" : {},
        incomeSlots: [
          {
            flex: 1,
            values: []
          }
        ],
        information: '请填写公司全称，如XX有限公司',
        infor: true
      }
    },
    watch: {
      company_name (newData) {
        if(newData.substring(newData.length-4) != '有限公司'){
          this.infor = true
        }else{
          this.infor = false
        }
      }
    },
    created () {
      let loopMap = (items, key, val) => {
        Object.keys(items[val].choice).forEach((item, idx) => {
          this[key].push({
            name: items[val].choice[item],
            eng: item,
            choose: true,
            isChoose: false
          })
        })
      }
      this.baseService.get('/trade/openAccountPara').then((res) => {
        loopMap(res.data, 'hunyins', 'marital')
        loopMap(res.data, 'jiuyes', 'employment')
        this.choice = res.data.industry.choice
        this.incomeChoice = res.data.income.choice
        this.setRadioState()
      })
    },
    mounted () {
      let h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
      let h1 = h - 60
      this.$refs.contentheight.style.height = h1 + 'px'
      Toast({
        message: '如果信息与身份证不一致,请手动填写相关内容',
        duration: 3000
      })
     let inputs = document.getElementsByTagName('input')
      Object.keys(inputs).forEach((item, idx) => {
        inputs[item].addEventListener('focus', () => {
          this.$refs.mykhhd.style.position = 'absolute'
        })
        inputs[item].addEventListener('blur', () => {
          this.$refs.mykhhd.style.position = 'fixed'
        })
      })
//
      let that = this
      axios({
        method: 'get',
        timeout: 60000,
        headers: {'Authorization':  window.localStorage.getItem('token')},
        url: host.host + '/api/v1/trade/personInfo'
      }).then(function(data){
        if(data.data.code === 6006) {
          that.$router.push('/login')
        }
        if(data.data.code == 6007){
          that.$refreshToken()
        }
        if(data.data.code ===200){
          let getData = data.data.data
          that.$store.state.openData = data.data.data
        }
      }).catch((err) => {
      })


//      行业

    },
    methods: {
      setRadioState () {
        let idMessage = this.$store.state.idmessage
        let getMessage = this.$store.state.openData
        if(this.$store.state.openData !== undefined && getMessage.marital) {
          this.idMessages.location = getMessage.id_addr_sheng
          this.id_addr_shi = getMessage.id_addr_shi
          this.id_addr = getMessage.id_addr
          this.email = getMessage.email
          this.raise_amount = getMessage.raise_amount
  //        婚姻
          for(let i = 0; i < this.hunyins.length; i++){
            if (getMessage.marital.toString() === this.hunyins[i].eng) {
              this.hunyins[i].isChoose = true
            }
          }
  //        就业
          for(let j = 0; j < this.jiuyes.length; j++){
            if (getMessage.employment.toString() === this.jiuyes[j].eng) {
              this.jiuyes[j].isChoose = true
            }
          }
  //        在家投资
          if(getMessage.employment === 'homeInvest') {
            this.wuye = true
            for (var k in this.incomeChoice){
              if (getMessage.income === k) {
                this.chooseIncomedata = this.incomeChoice[k]
                this.engChooseIncome = k
              }
            }
          }else{
            this.companyShow = true
            this.company_name = getMessage.company_name
            this.province = getMessage.company_addr_sheng
            this.city = getMessage.company_addr_shi
            this.company_addr = getMessage.company_addr
            for(var i in this.choice) {
              if (i === getMessage.industry) {
                this.chooseIndustry = this.choice[i]
                this.engChooseIndustry = i
              }
            }
            this.position = getMessage.position
          }
        }
        if(JSON.stringify(this.$store.state.idmessage) != "{}") {
          //      身份证信息处理

          this.message = this.$store.state.idmessage
          this.idMessages.name = idMessage.words_result.姓名.words
          this.idMessages.na_first = idMessage.words_result.姓名.words.substring(0,1)
          this.idMessages.na_last = idMessage.words_result.姓名.words.substring(1,idMessage.words_result.姓名.words.length)
          this.idMessages.idcard = idMessage.words_result.公民身份号码.words
          this.idMessages.surname = pinyinUtil.getPinyin(idMessage.words_result.姓名.words[0],'',false,false)
          this.idMessages.firstname = pinyinUtil.getPinyin(idMessage.words_result.姓名.words.substring(1,idMessage.words_result.姓名.words.length),'',false,false)
  //      省份
  //        let province = ''
  //        let position = idMessage.words_result.住址.words
  //        if(position.indexOf('省')!==-1){
  //          province = position.substring(0,position.indexOf('省')) + '省'
  //        }else if(position.indexOf('市')!==-1){
  //          province = position.substring(0,position.indexOf('市')) + '市'
  //        }
  //        this.idMessages.location = province
        }else if (JSON.stringify(this.$store.state.openData) != "{}"){

          this.idMessages.na_first = getMessage.na_first
          this.idMessages.na_last = getMessage.na_last
          this.idMessages.surname = getMessage.py_first
          this.idMessages.firstname = getMessage.py_last
          this.idMessages.idcard = getMessage.id_number

        }


      },
//      婚姻状况
      clickThis (index) {
        document.getElementById('open3Content').scrollTop = document.getElementById('open3Content').scrollTop + 70
        for(let i = 0; i<this.hunyins.length; i++){
          this.hunyins[i].choose = true
          this.hunyins[i].isChoose = false
        }
        this.hunyins[index].choose = !this.hunyins[index].choose
        this.hunyins[index].isChoose = !this.hunyins[index].isChoose

      },
//      就业状况
      clickWork (item, index) {
        document.getElementById('open3Content').scrollTop = document.getElementById('open3Content').scrollTop + 400
        for(let i = 0; i<this.jiuyes.length; i++){
          this.jiuyes[i].choose = true
          this.jiuyes[i].isChoose = false
        }
        // if (item === 0 || item === 1){
        //   this.companyShow = true
        //   this.wuye = false
        // }else if(index === 2){
        //   this.wuye = true
        //   this.companyShow = false
        // }
        if (item.eng === 'homeInvest') {
          this.companyShow = false
          this.wuye = true
        } else {
          this.wuye = false
          this.companyShow = true
        }
        this.jiuyes[index].choose = !this.jiuyes[index].choose
        this.jiuyes[index].isChoose = !this.jiuyes[index].isChoose
      },
//      公司地址
      onAddressChange(picker, values) {
        let sheng = Object.keys(s)
        let shi = Object.keys(s[values[0]])
        picker.setSlotValues(1, shi)
        this.province = values[0]
        this.city = values[1]
      },
      choosePro () {
        this.mtPickerShow1 = true
        this.popupVisible1 = true
      },
//      身份证地址
      chooseHome () {
        this.mtPickerShow0 = true
        this.popupVisible0 = true
      },
      onHomeChange(picker, values) {
        let sheng = Object.keys(s)
        let shi = Object.keys(s[values[0]])
        picker.setSlotValues(1, shi)
        this.idMessages.location = values[0]
        this.id_addr_shi = values[1]
      },
//      行业
      chooseIndu () {
        this.industrySlots[0].values = []
        this.xiangxia2 = !this.xiangxia2
        this.xiangyou2 = !this.xiangyou2
        this.mtPickerShow2 = true
        this.popupVisible2 = true
        for(var i in this.choice) {
          this.industrySlots[0].values.push(this.choice[i])
        }
      },
      onIndustryChange (picker,value) {
        for(var i in this.choice) {
          if(this.choice[i] === value[0]){
            this.engChooseIndustry = i
          }
        }
        this.chooseIndustry = value[0]
      },
//      选择收入来源
      chooseIncome () {
        this.incomeSlots[0].values = []
        this.incomeShow = !this.incomeShow
        this.mtPickerShow3 = true
        this.popupVisible3 = true
        for(var i in this.incomeChoice) {
          this.incomeSlots[0].values.push(this.incomeChoice[i])
        }
      },
      onIncomeChange (picker,value) {
        this.chooseIncomedata = value[0]
        for(var i in this.incomeChoice) {
          if(this.incomeChoice[i] === value[0]){
            this.engChooseIncome = i
          }
        }
      },
      next () {
        let that = this
//        向后台发送的数据
//        婚姻状态
        let marital,employment
        for(let i = 0; i < that.hunyins.length; i++){
          if (that.hunyins[i].isChoose === true) {
            marital = that.hunyins[i].eng
          }
        }
        for(let j = 0; j < that.jiuyes.length; j++){
          if (that.jiuyes[j].isChoose === true) {
            employment = that.jiuyes[j].eng
          }
        }
        for(var k in that.idMessages){
          if(that.idMessages[k] === null || that.idMessages[k] === ''){
            Toast({
              message: '请输入完整身份证信息',
              duration: 1000
            })
            return
          }
        }
        let code = this.idMessages.idcard
        var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
        if(!code || !/^[1-9][0-9]{5}(19[0-9]{2}|200[0-9]|2010)(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])[0-9]{3}[0-9xX]$/i.test(code)){
          Toast({
            message: '身份证号格式错误',
            duration: 1000
          })
          return false
        }
        else if(!city[code.substr(0,2)]){
          Toast({
            message: '身份证地址编码错误',
            duration: 1000
          })
          return false
        }
        else{
          //18位身份证需要验证最后一位校验位
          if(code.length == 18){
            code = code.split('');
            //∑(ai×Wi)(mod 11)
            //加权因子
            var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
            //校验位
            var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
            var sum = 0;
            var ai = 0;
            var wi = 0;
            for (var i = 0; i < 17; i++)
            {
              ai = code[i];
              wi = factor[i];
              sum += ai * wi;
            }
            var last = parity[sum % 11];
            if(parity[sum % 11] != code[17]){
              Toast({
                message: '身份证格式错误',
                duration: 1000
              })
              return false
            }
          }
        }
        if(that.idMessages.location === null || that.idMessages.location === ''){
          Toast({
            message: '请输入市',
            duration: 1000
          })
          return
        }
        if(that.idMessages.location === '请选择省') {
          Toast({
            message: '请选择省',
            duration: 1000
          })
          return
        }

        if(that.id_addr_shi === null || !that.id_addr_shi || that.id_addr_shi == 'undefined'){
          Toast({
            message: '请输入市',
            duration: 1000
          })
          return
        }
        if(that.id_addr_shi === '请选择市'){
          Toast({
            message: '请输入市',
            duration: 1000
          })
          return
        }
        if(that.id_addr === null || that.id_addr === ''){
          Toast({
            message: '请输入详细地址',
            duration: 1000
          })
          return
        }

        if(that.email === null || that.email === ''){
          Toast({
            message: '请输入邮箱',
            duration: 1000
          })
          return
        }else if(that.email.indexOf('@')===-1){
          Toast({
            message: '请输入正确的邮箱',
            duration: 1000
          })
          return
        }
        if(that.raise_amount === null || that.raise_amount === ''){
          Toast({
            message: '请输入抚养人数',
            duration: 1000
          })
          return
        }
        if(marital === null || marital === ''){
          Toast({
            message: '请选择婚姻状况',
            duration: 1000
          })
          return
        }
        if(employment === null || employment === ''){
          Toast({
            message: '请选择就业状况',
            duration: 1000
          })
          return
        }


        let sendData = new FormData()
        if(that.$store.state.type == 'adviser') {
          sendData.append("account_type", 'adviser')
        }else if(that.$store.state.type == 'trade'){
          sendData.append("account_type", 'trade')
        }
        sendData.append("na_first", that.idMessages.na_first)
        sendData.append("na_last", that.idMessages.na_last)
        sendData.append("py_first", that.idMessages.surname.toUpperCase())
        sendData.append("py_last", that.idMessages.firstname.toUpperCase())
        sendData.append("id_number", that.idMessages.idcard)
        sendData.append("id_addr_sheng", that.idMessages.location)
        sendData.append("id_addr_shi", that.id_addr_shi)
        sendData.append("id_addr", that.id_addr)
        sendData.append("email", that.email)
        sendData.append("raise_amount", that.raise_amount)
        sendData.append("marital", marital)
        sendData.append("employment", employment)
        if(employment === "homeInvest") {
          if(that.chooseIncomedata === '点击选择'){
            Toast({
              message: '请选择收入来源',
              duration: 1000
            })
            return
          }
          sendData.append("income", that.engChooseIncome)
        } else {
          if(that.company_name === null || that.company_name === ''){
            Toast({
              message: '请输入公司名称',
              duration: 1000
            })
            return
          } else {
            if(that.company_name.substring(that.company_name.length-4) !== '有限公司'){
              Toast({
                message: '公司名称必须以"有限公司"结尾',
                duration: 2000
              })
              return
            }
          }
          if(that.province === '请选择省份'){
            Toast({
              message: '请选择公司省份',
              duration: 1000
            })
            return
          }
          if(that.city === '请选择市' || that.city === undefined){
            Toast({
              message: '请选择公司市',
              duration: 1000
            })
            return
          }
          if(that.company_addr === null || that.company_addr === ''){
            Toast({
              message: '请输入公司详细地址',
              duration: 1000
            })
            return
          }
          if(that.chooseIndustry === '点击选择'){
            Toast({
              message: '请选择公司行业',
              duration: 1000
            })
            return
          }
          if(that.position === null || that.position === ''){
            Toast({
              message: '请输入职位',
              duration: 1000
            })
            return
          }
          sendData.append("company_name", that.company_name)
          sendData.append("company_addr_sheng", that.province)
          sendData.append("company_addr_shi", that.city)
          sendData.append("company_addr", that.company_addr)
          sendData.append("industry", that.engChooseIndustry)
          sendData.append("position", that.position)
        }
        axios({
          method: 'post',
          headers: {'Authorization': window.localStorage.getItem('token')},
          url: host.host + '/api/trade/personInfo',
          data: sendData
        }).then(function (data) {
          if(data.data.code === 6006) {
            that.$router.push('/login')
          }
          if(data.data.code === 6007){
            that.$refreshToken()
          }
          if(data.data.code === 200){
            that.$router.push('/open4')
          }else{
            Toast({
              message: data.data.msg,
              duration: 1000
            })
          }
        }).catch(function (err) {
        })
      },

      IdentityCodeValid (code) {

      },
      goBack () {
        this.$router.push('./open2')
      },
      contact () {
        window.location.href = 'tel:400-900-6687'
      }
    }
  }
</script>
